// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import Vuex from 'vuex'
import FastClick from 'fastclick'
import VueRouter from 'vue-router'
import router from './router'
import App from './App'
import CommonFunction from './plugins/CommonFunction/index.js'
import TransitPlugin from './plugins/Transit/index.js'
import {ToastPlugin, dateFormat, AlertPlugin, ConfirmPlugin} from 'vux'
import iView from 'iview'
// import 'iview/dist/styles/iview.css'

import '../static/css/style.css'
import '../static/css/index.css'
import '../static/css/swiper.css'
import '../static/css/RYindex.css'
import VueAwesomeSwiper from 'vue-awesome-swiper'
import ElementUI from 'element-ui'
import '../static/UE/ueditor.config.js'
import '../static/UE/ueditor.all.js'
import '../static/UE/lang/zh-cn/zh-cn.js'
import '../static/UE/ueditor.parse.js'

let Jquery = require('jquery')
Vue.use(ElementUI)
Vue.use(iView)
Vue.use(VueRouter)
Vue.use(CommonFunction)
Vue.use(TransitPlugin)
Vue.use(AlertPlugin)
Vue.use(ConfirmPlugin)
Vue.use(ToastPlugin)
Vue.use(Vuex)
Vue.$chaos.config('mode', 'client')
Vue.$chaos.config('callbackUrl', 'http://admin.pangukj.com/callback.php')
Vue.use(VueAwesomeSwiper)
// Vue.$chaos.config('baseUrl', '/api/dean')
// let indexUrl = './app.html#/'
Vue.$chaos.config('baseUrl', '/api')
let indexUrl = '/#/'

Vue.$chaos.config('loginUrl', indexUrl + 'Login')
Vue.$chaos.config('indexUrl', indexUrl)
Vue.$chaos.config('verifyFail', function (type) {
  if (type && type.info === 'customAuthFail') {
    Vue.$chaos.transit.warning({
      title: '没有权限',
      info: '您当前没有该操作的权限！',
      confirm: function () {
        Vue.$chaos.transit.hide()
        location.href = indexUrl
      }
    })
  } else {
    Vue.$chaos.transit.warning({
      title: '授权失败',
      info: '没有正确获得您的用户信息，请重试',
      confirm: function () {
        Vue.$chaos.transit.hide()
        location.href = indexUrl + 'Login'
      }
    })
  }
})
Vue.$chaos.config('customAuth', function (modules) {
  if (modules) {
    let userinfo = Vue.$chaos.getUserInfo()
    if (Jquery.inArray(modules, userinfo.r_role) < 0) {
      return false
    } else {
      return true
    }
  }
  return true
})
Vue.$chaos.config('wxConfig', {
  /* appid: 'wx93abf51bb1202e3f',
  scope: 'snsapi_base' */
  scope: 'snsapi_base',
  appid: 'wxd86a4926f1527101',
  agentid: '1000002'
})
// console.log(Vue.$chaos)
Vue.filter('date', function (value) {
  return dateFormat(new Date(parseInt(value) * 1000), 'YYYY-MM-DD')
})
Vue.filter('datetime', function (value) {
  return dateFormat(new Date(parseInt(value) * 1000), 'YYYY-MM-DD HH:mm')
})
Vue.$chaos.checkAuth = function (module) {
  let userinfo = Vue.$chaos.getUserInfo()
  return Jquery.inArray(module, userinfo.r_role) > -1
}

FastClick.attach(document.body)

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  router,
  render: h => h(App)
}).$mount('#app-box')

Vue.prototype.isMobile = function (mobile) {
  return /^1[345789]\d{9}$/.test(mobile)
}

